<template>
    <div class="app-container">
        <!-- 查询条件开始 -->
        <el-form ref="queryForm" :model="queryParams" :inline="true" label-width="98px">
            <el-form-item label="患者姓名" prop="patientName">
                <el-input
                        v-model="queryParams.patientName"
                        placeholder="请输入患者姓名"
                        clearable
                        size="small"
                        style="width:240px"
                />
            </el-form-item>
            <el-form-item label="挂号单号" prop="regId">
                <el-input
                        v-model="queryParams.regId"
                        placeholder="请输入挂号单号"
                        clearable
                        size="small"
                        style="width:240px"
                />
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button type="primary" icon="el-icon-refresh" size="mini"  @click="resetSearchForm">重置</el-button>
            </el-form-item>
        </el-form>

        <!-- 数据表格开始 -->
        <el-table  border :data="orderBackfeeTableList">
            <el-table-column label="退费订单号" align="center" width="210" prop="backId" />
            <el-table-column label="挂号单号" align="center" width="200" prop="regId" />
            <el-table-column label="患者姓名" align="center" prop="patientName" />
            <el-table-column label="总金额" align="center" prop="backAmount" />
            <el-table-column label="退费类型" align="center" prop="backType"  :formatter="typeFormatter"/>
            <el-table-column label="订单状态" prop="backStatus" align="center" :formatter="statusFormatter" />
            <el-table-column label="创建时间" align="center" prop="createTime" />
            <el-table-column label="操作" width="300px" align="center">
                <template slot-scope="scope">
                    <el-button type="text" icon="el-icon-view" size="mini" @click="handleViewItem(scope.row)">查看详情</el-button>
                </template>
            </el-table-column>
        </el-table>
        <!-- 分页控件开始 -->
        <el-pagination
                v-show="total>0"
                :current-page="currentPage"
                :page-sizes="[5, 10, 20, 30]"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
        />
        <!-- 分页控件结束 -->

        <!-- 数据表格结束 -->
        <!-- 查看详情的弹出层开始 -->
        <el-dialog
                :title="title"
                :visible.sync="open"
                width="1000px"
                center
                append-to-body
        >
            <el-table border :data="orderBackfeeItemList">
                <el-table-column label="详情ID" align="center" width="210" prop="itemId" />
                <el-table-column label="处方ID" align="center" width="200" prop="coId" />
                <el-table-column label="名称" align="center" prop="itemName" />
                <el-table-column label="价格" align="center" prop="itemPrice" />
                <el-table-column label="数量" align="center" prop="itemNum" />
                <el-table-column label="小计" prop="itemAmount" align="center" />
                <el-table-column label="类型" align="center" prop="itemType">
                    <template slot-scope="scope">
                        {{ scope.row.itemType==='0'?'药品':'检查' }}
                    </template>
                </el-table-column>
                <el-table-column label="状态" align="center" prop="status" :formatter="itemStatusFormat"/>
            </el-table>
            <span slot="footer" class="dialog-footer">
                  <el-button @click="open=false">关 闭</el-button>
            </span>
        </el-dialog>
<!--         查看详情的弹出层结束-->

    </div>
</template>

<script>
    export default {
        name: "Backfeelist",
        data(){
            return{
                //数据表格内容
                orderBackfeeTableList : [],
                // 查询参数
                queryParams: {
                    patientName: undefined,
                    regId: undefined
                },
                // 分页
                total: 0,
                pageSize: 5,
                currentPage:1,

                //数据字典 支付状态
                typeOptions:[],
                //数据字典 类型
                statusOptions:[],
                backstatusOptions:[],

                //查看详情是否出现
                open: false,
                //详情里面的数据
                orderBackfeeItemList:[],
                //详情中状态
                itemStatusOptions:[],
                // 弹出层标题
                title: '',
            }
        },
        methods:{
            //查询所有数据
            initQuery() {
                this.$axios.post("/charge/api/orderBackfee/queryBackgee/"+this.currentPage+"/"+this.pageSize,this.queryParams).then(result=>{
                    this.orderBackfeeTableList=result.data.t.records;
                    this.total=result.data.t.total;
                })
            },

            //查询表格中数据
            handleQuery(){
                this.currentPage=1
                this.initQuery();
            },
            // //查询退费类型
            initType(){
                this.$axios.get("/charge/api/orderBackfee/getByType/his_pay_type_status").then(r=>{
                    this.typeOptions=r.data.t;
                })
            },
            //对类型格式化解析
            typeFormatter(row){
                let v=row.backType;
                return this.formatDict(this.typeOptions,v);
            },
            //查询退费状态
            initStatus(){
                this.$axios.get("/charge/api/orderBackfee/getByType/his_backfee_status").then(r=>{
                    this.backstatusOptions=r.data.t;
                })
            },
            //对状态解析
            statusFormatter(row){
                let v=row.backStatus;
                return this.formatDict(this.backstatusOptions,v);
            },

            //查看详情
            handleViewItem(row){
                this.open=true;
                this.title = '查询' + row.patientName + '退费详情';
                this.$axios.get("charge/api/orderBackfeeItem/allBackfeeItem/"+row.backId).then(r=>{
                    this.orderBackfeeItemList= r.data.t;
                })
            },
            //查询详情中的状态
            initItemStatus(){
                this.$axios.get("/charge/api/orderBackfee/getByType/his_order_details_status").then(r=>{
                    this.statusOptions=r.data.t;
                })
            },
            itemStatusFormat(row){
                return this.formatDict(this.statusOptions, row.status)
            },


            // 分页pageSize变化时触发
            handleSizeChange(val) {
                this.pageSize = val
                // 重新查询
                this.initQuery()
            },
            // 点击上一页  下一页，跳转到哪一页面时触发
            handleCurrentChange(val) {
                this.currentPage = val
                // 重新查询
                this.initQuery()
            },
            //重置
            resetSearchForm(){
                this.queryParams={};
                this.handleQuery();
            },
        },
        created(){
            //加载查询表格数据
            this.handleQuery();
            //支付类型
            this.initType();
            //订单状态
            this.initStatus();
            //详情中状态
            this.initItemStatus();

            //查询所有
            this.initQuery();
        }
    }
</script>

<style scoped>

</style>
